package com.example.controller;

/**
 * 功能：
 * 作者：snake
 * 日期：2024/2/4 下午 11:32
 */
import com.example.common.Result;
import com.example.entity.Comment;
import com.example.service.CommentService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 评价表前端操作接口
 **/
@RestController
@RequestMapping("/comment")
public class CommentController {

  @Resource
  private CommentService commentService;

  /**
   * 新增
   */
  @PostMapping("/add")
  public Result add(@RequestBody Comment comment) {
    commentService.add(comment);
    return Result.success();
  }

  /**
   * 删除
   */
  @DeleteMapping("/delete/{id}")
  public Result deleteById(@PathVariable Integer id) {
    commentService.deleteById(id);
    return Result.success();
  }

  /**
   * 批量删除
   */
  @DeleteMapping("/delete/batch")
  public Result deleteBatch(@RequestBody List<Integer> ids) {
    commentService.deleteBatch(ids);
    return Result.success();
  }

  /**
   * 修改
   */
  @PutMapping("/update")
  public Result updateById(@RequestBody Comment comment) {
    commentService.updateById(comment);
    return Result.success();
  }

  /**
   * 根据ID查询
   */
  @GetMapping("/selectById/{id}")
  public Result selectById(@PathVariable Integer id) {
    Comment comment = commentService.selectById(id);
    return Result.success(comment);
  }

  /**
   * 查询所有
   */
  @GetMapping("/selectAll")
  public Result selectAll(Comment comment) {
    List<Comment> list = commentService.selectAll(comment);
    return Result.success(list);
  }

  /**
   * 分页查询
   */
  @GetMapping("/selectPage")
  public Result selectPage(Comment comment,
                           @RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "10") Integer pageSize) {
    PageInfo<Comment> page = commentService.selectPage(comment, pageNum, pageSize);
    return Result.success(page);
  }

  /**
   * 查询用户或者骑手的评价信息
   */
  @GetMapping("/selectComment/{userId}")
  public Result selectComment(@PathVariable Integer userId) {
    List<Comment> list = commentService.selectComment(userId);
    return Result.success(list);
  }

}